import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/api/oauth/user/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/api/oauth/user/info',
    method: 'get',
    params: { access_token: token }
  })
}

export function getUserMenu(token, systemCode) {
  return request({
    url: '/api/oauth/user/menu/' + systemCode,
    method: 'get',
    params: { access_token: token }
  })
}

export function logout() {
  return request({
    url: '/api/oauth/user/logout',
    method: 'get'
  })
}

//------------------------------------------------------------------------------
// 系统管理 start

//查询人员列表
export function findUserList(username, comCode, systemCode, page, size) {
  return request({
    url: '/api/user/sm/findList',
    method: 'get',
    params: { username: username, comCode: comCode, systemCode: systemCode, page: page, size: size }
  })
}

//获取对应系统的菜单
export function getSystemMenu(systemCode) {
  return request({
    url: '/api/user/sm/getSystemMenu/' + systemCode,
    method: 'get'
  })
}

//获取对应系统的菜单
export function addMenu(systemCode, parentId, name, title, path, icon, redirect, sortId) {
  return request({
    url: '/api/user/sm/addMenu/',
    method: 'post',
    params: {
      systemCode: systemCode,
      parentId: parentId,
      name: name,
      title: title,
      path: path,
      sortId: sortId,
      icon: icon,
      redirect: redirect,
    }
  })
}

//获取对应系统角色
export function getRoleList(systemCode, page, size) {
  return request({
    url: '/api/user/sm/getRoleList',
    method: 'get',
    params: {
      systemCode: systemCode,
      page: page,
      size: size
    }
  })
}

//获取某个用户角色权限
export function getRoles(systemCode, userId) {
  return request({
    url: '/api/user/sm/getRoles',
    method: 'get',
    params: {
      systemCode: systemCode,
      userId: userId,
    }
  })
}

//更新某个用户的角色列表
export function updateUserRole(data) {
  return request({
    url: '/api/user/sm/updateUserRole',
    method: 'post',
    data
  })
}

//添加角色
export function addRole(data) {
  return request({
    url: '/api/user/sm/addRole',
    method: 'post',
    data
  })
}

//更新角色
export function updateRole(data) {
  return request({
    url: '/api/user/sm/updateRole',
    method: 'post',
    data
  })
}

//获取用户的菜单
export function getMenus(systemCode, username) {
  return request({
    url: '/api/user/sm/getMenus',
    method: 'get',
    params: {
      systemCode: systemCode,
      username: username
    }
  })
}

//更新某个用户的菜单列表
export function updateUserMenu(data) {
  return request({
    url: '/api/user/sm/updateUserMenu',
    method: 'post',
    data
  })
}

// 删除菜单
export function deleteMenu(systemCode, menuId) {
  return request({
    url: '/api/user/sm/deleteMenu',
    method: 'post',
    params: {
      systemCode: systemCode,
      menuId: menuId
    }
  })
}

//更新菜单
export function updateMenu(data) {
  return request({
    url: '/api/user/sm/updateMenu',
    method: 'post',
    data
  })
}updateMenu

// 系统管理 end
// ------------------------------------------------------------
